package cn.highedu.spring.config;

import cn.highedu.spring.bean.AccountRepository;
import cn.highedu.spring.bean.JdbcAccountRepository;
import cn.highedu.spring.bean.TransferService;
import cn.highedu.spring.bean.TransferServiceImpl;
import cn.highedu.spring.bean17.CustomBeanPostProcessor;
import cn.highedu.spring.bean17.MyConfigurationCustomizer;
import org.apache.commons.dbcp2.BasicDataSource;
import org.springframework.beans.factory.config.BeanPostProcessor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import javax.sql.DataSource;

/**
 * 显式定义Bean
 */
@Configuration
public class TransferModuleConfig {
    @Bean
    public TransferService transferService() {
        return new TransferServiceImpl(accountRepository());
    }
    @Bean
    public AccountRepository accountRepository() {
        return new JdbcAccountRepository(dataSource());
    }
    @Bean
    public DataSource dataSource() {
        BasicDataSource dataSource = new BasicDataSource();
        dataSource.setUrl("jdbc:mysql://localhost:3306/spring_test?characterEncoding=utf8&useSSL=false&serverTimezone=Asia/Shanghai&rewriteBatchedStatements=true");
        dataSource.setUsername("root");
        dataSource.setPassword("root");
        return dataSource;
    }
}
